<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>


<script type="text/javascript" language="javascript">
    var combothajaranStorePay = createStore(false, 'mcombothajaranStorePay',['id_th_ajaran','tahun_ajaran'],'<?php echo base_url(); ?>' + 'tahunajaran/get_rows_combo');
    var semesterstorePay =createArrayStore([['I','Ganjil'],['II','Genap']]);
    var combo_bulan_StorePay=createArrayStore2( ['num', 'name'],bulan_data);
    var combo_bulan_StorePayB=createArrayStore2( ['num', 'name'],bulan_data);
    var comboKelasStorePay = createStore(false, 'mcomboKelasStorePay', ['kd_kelas','keterangan'], '<?php echo base_url(); ?>' + 'masterkelas/get_rows_combo');
    var baseUrlPay='base_report/payment_print?idthajaran=';
    var printUrlPay='';
    defineTwinSiswa_windows('winfindsiswapay', 'winfindsiswapay_id', twinsiswaBaseStore, function(){			
        var sm = this.getSelectionModel();
        var sel = sm.getSelection();
        //                console.log('doublekil');
        if (sel.length > 0) {	
            Ext.getCmp('pay_nis').setValue(sel[0].get('nis'));  
            Ext.getCmp('pay_nama').setValue(sel[0].get('nama'));  
            Ext.getCmp('pay_kd_kelas').setValue(sel[0].get('kd_kelas'));  
            Ext.getCmp('winfindsiswapay_id').close();            
        }
    });
    defineTabFormDynamis(
    {
        name:'MyTabDaftarPembayaranPiutang',
        xtype:'TabDaftarPembayaranPiutang',
        alias:'widget.TabDaftarPembayaranPiutang',
        title:'Daftar Pembayaran Piutang',
        id:'tab18'
        ,items:[
            {
                xtype: 'form',
                autoShow: true,
                id: 'panelpay',
                region: 'north',
                margins: '5 5 5 5',
                layout: 'column',                
                items:[
                    {
                        xtype: 'form',
                        columnWidth: .3,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 85,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype:'combo',
                                afterLabelTextTpl: required_css,
                                name: 'id_th_ajaran',
                                id: 'pay_id_th_ajaran',
                                fieldLabel: 'Tahun Ajaran',                                    
                                //                    labelWidth: 80,
                                emptyText: 'Tahun Ajaran'
                                ,mode:'local',
                                store: combothajaranStorePay,
                                valueField: 'id_th_ajaran',
                                displayField: 'tahun_ajaran',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: false,
                                editable: false  ,
                                hiddenName:'id_th_ajaran'
                                ,listeners:{
                                    select:function(cmb,rec){
                                        console.log(rec[0].get('tahun_ajaran'));
                                    }
                                }
                            },
                            {
                                xtype: 'combo',                                                            
                                //                                tooltip: 'Field tidak boleh kosong',
                                //                                afterLabelTextTpl: required_css,
                                fieldLabel: 'Semester',                        
                                id: 'pay_semester',
                                mode:'local',
                                store: semesterstorePay,
                                valueField: 'mid',
                                displayField: 'mtext',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: true,
                                editable: false,                                
                                emptyText: 'Semester'    ,
                                name:'semester',
                                hiddenName:'semester'
                            },{
                                xtype:'fieldcontainer',
                                fieldLabel:'ThBl Periode',
                                //                    labelWidth: 130,
                                layout: 'hbox',                    
                                defaultType: 'textfield',                    
                                //                    margin: '0 0 5 0',
                                defaults: {
                                    labelWidth: 80,
                                    labelAlign: 'right'
                                    ,hideLabel: 'true'
                                },
                                //                        tooltip: 'Field tidak boleh kosong',
                                //                        afterLabelTextTpl: required_css,
                                items: [
                                    {
                                        xtype:'numberfield',
                                        name:'tahun',
                                        fieldLabel:'Tahun',
                                        id: 'pay_tahun_p',
                                        emptyText:'Tahun',
                                        allowBlank: true,                                                                        
                                        //                            hideTrigger: true,
                                        fieldStyle: 'text-align: right;',
                                        minValue: new Date().getFullYear()
                                        ,flex:1
                                    },
                                    {
                                        xtype: 'combobox',
                                        name: 'bulan',
                                        id: 'pay_bulan_p',
                                        displayField: 'name',
                                        valueField: 'num',
                                        queryMode: 'local',
                                        emptyText: 'Bulan',
                                        hiddenName:'bulan',
                                        //                            margins: '0 6 0 0',
                                        store: combo_bulan_StorePay,
                                        width: 100,
                                        allowBlank: true,
                                        forceSelection: true
                                        ,flex:1
                                    }
                                ]
                            }  
                        ]
                    },
                    {
                        xtype: 'form',
                        columnWidth: .3,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 80,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype: 'twincombo'
                                ,name: 'nis'
                                ,fieldLabel: 'NIS',
                                //                                tooltip: 'Field tidak boleh kosong',
                                //                                afterLabelTextTpl: required_css,
                                id:'pay_nis',
                                store:twinsiswaBaseStore,
                                menu:'winfindsiswapay',
                                enableKeyEvents:true,
                                emptyText:'Entry / Pilih Siswa',
                                allowBlank:true
                                ,listeners:{
                                    keyup: function(f,e,opt) { 
                                        if (e.getKey()==113){
                                            f.onTrigger1Click();
                                        }          
                                        if (e.getKey()==13){
                                            if(f.getValue().length>0){
                                                var rec=  findNis(f.getValue(), allsiswaStoredbs);                                                
                                                if(rec){
                                                    Ext.getCmp('pay_nama').setValue(rec.get('nama'));
                                                    Ext.getCmp('pay_kd_kelas').setValue(rec.get('kd_kelas'));
                                                    //                                                    Ext.getCmp('sim_th_ajaran').focus();
                                                }else{
                                                    set_message(2,'Data Siswa Tidak Terdaftar !!!');
                                                    f.setValue('');
                                                }
                                            };
                                        }
                                    }
                                }
                                //                    ,readOnly:true                                    
                            },{
                                name: 'nama',
                                id: 'pay_nama',
                                fieldLabel: 'Nama Siswa',
                                maxLength:50,
                                emptyText: 'Nama Siswa',
                                allowBlank: true
                                ,readOnly:true                    
                            },{
                                xtype: 'combo',                        
                                name:'kd_kelas',
                                //                                    tooltip: 'Field tidak boleh kosong',
                                //                                    afterLabelTextTpl: required_css,
                                fieldLabel: 'Kelas',                        
                                id: 'pay_kd_kelas',
                                mode:'local',
                                store: comboKelasStorePay,
                                valueField: 'kd_kelas',
                                displayField: 'keterangan',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: true,
                                editable: true,                                    
                                hiddenName: 'kd_kelas',
                                margins: '0 0 0 5',
                                emptyText: 'Pilih Kelas'

                            }
                        ]
                    },
                    {
                        xtype: 'form',
                        columnWidth: .3,
                        layout: 'form',
                        border: false,
                        labelWidth: 80,
                        bodyPadding: '5 5 5 5',
                        defaultType     : 'textfield',
                        defaults: { 
                            
                            allowBlank: false,
                            labelWidth: 90,
                            labelAlign: 'left',
                            anchor:'90%'
                        },
                        items :[
                            {
                                xtype: 'datefield',
                                name: 'tgl_awal',
                                allowBlank: true, 
                                vtype:'daterange',
                                endDateField: 'pay_tgl_akhir',
                                afterLabelTextTpl: required_css,
                                fieldLabel: 'Tanggal Awal',
                                format:'d F Y',
                                anchor: '90%'
                                ,id:'pay_tgl_awal'
                            },
                            {
                                xtype: 'datefield',
                                name: 'tgl_akhir',
                                allowBlank: true, 
                                vtype:'daterange',                                
                                startDateField:  'pay_tgl_awal',
                                afterLabelTextTpl: required_css,
                                fieldLabel: 'Tanggal Akhir',
                                anchor: '90%',
                                format:'d F Y'
                                ,id:'pay_tgl_akhir'
                            }
                            ,{
                                xtype:'fieldcontainer',
                                fieldLabel:'ThBl Bayar',
                                //                    labelWidth: 130,
                                layout: 'hbox',                    
                                defaultType: 'textfield',                    
                                //                    margin: '0 0 5 0',
                                defaults: {
                                    labelWidth: 80,
                                    labelAlign: 'right'
                                    ,hideLabel: 'true'
                                },
                                //                        tooltip: 'Field tidak boleh kosong',
                                //                        afterLabelTextTpl: required_css,
                                items: [
                                    {
                                        xtype:'numberfield',
                                        name:'tahunb',
                                        fieldLabel:'Tahun',
                                        id: 'pay_tahun_b',
                                        emptyText:'Tahun',
                                        allowBlank: true,                                                                        
                                        //                            hideTrigger: true,
                                        fieldStyle: 'text-align: right;',
                                        minValue: new Date().getFullYear()
                                        ,flex:1
                                    },
                                    {
                                        xtype: 'combobox',
                                        name: 'bulanb',
                                        id: 'pay_bulan_b',
                                        displayField: 'name',
                                        valueField: 'num',
                                        queryMode: 'local',
                                        emptyText: 'Bulan',
                                        hiddenName:'bulan',
                                        //                            margins: '0 6 0 0',
                                        store: combo_bulan_StorePayB,
                                        width: 100,
                                        allowBlank: true,
                                        forceSelection: true
                                        ,flex:1
                                    }
                                ]
                            }  
                        ]
                    }
                ],
                tbar:[
                    {
                        xtype: 'button',
                        id:'btn_pay_reset',
                        text: 'Reset',
                        iconCls: 'icon-refresh',
                        onClick: function(btn){
                                                        getComp('panelpay').getForm().reset();
//                            var frm1=getComp('panelpay').getForm().getValues();
//                            readLog(frm1.id_th_ajaran);
                        }
                    }
                ],
                bbar:[
                    {
                        xtype: 'button',
                        id:'btn_pay_tampilkan',
                        text: 'Tampilkan',
                        iconCls: 'icon-preview_report',
                        //                        enableToggle: true,
                        onClick: function(btn){
                            printUrlPay='';
                            if(!getComp('panelpay').getForm().isValid()){
                                set_message(1, 'Pilihan Tidak Valid!!!');
                                return;
                            }else{
                                var frmvalue=getComp('panelpay').getForm().getValues();
                                if(!frmvalue.id_th_ajaran){
                                    set_message(1, 'Tahun Ajaran Belum Diisi!!');
                                    return;
                                }else{
                                    printUrlPay=baseUrlPay;
                                    printUrlPay +=frmvalue.id_th_ajaran;
                                    printUrlPay +='&thajaran=' + getComp('pay_id_th_ajaran').getRawValue() ;
                                    
                                }
                                if(frmvalue.semester){
                                    printUrlPay +='&idsemester=' + frmvalue.semester ;
                                    printUrlPay +='&semester=' + getComp('pay_semester').getRawValue() ; ;
                                }
                                if(frmvalue.tahun && frmvalue.bulan){
                                    var thbl=setThbl(frmvalue.tahun, frmvalue.bulan);
                                    printUrlPay +='&thblp=' + thbl ;
                                    
                                }
                                if(frmvalue.nis){
                                    printUrlPay +='&nis=' + frmvalue.nis ;
                                }
                                
                                if(frmvalue.kd_kelas){
                                    printUrlPay +='&kelas=' + frmvalue.kd_kelas ;
                                }
                                
                                if(frmvalue.tgl_awal){
                                    printUrlPay +='&tglawal=' + format_date(new Date(frmvalue.tgl_awal), 'Y-m-d')  ;
                                }
                                if(frmvalue.tgl_akhir){
                                    printUrlPay +='&tglakhir=' + format_date(new Date(frmvalue.tgl_akhir), 'Y-m-d') ;
                                }
                                if(frmvalue.tahunb && frmvalue.bulanb){
                                    var thbl=setThbl(frmvalue.tahunb, frmvalue.tahunb);
                                    printUrlPay +='&thblb=' + thbl ;
                                    
                                }
//                                readLog(format_date(new Date(frmvalue.tgl_akhir), 'Y-m-d'));
                                readLog(printUrlPay);
                                
                                to_print('printpay', printUrlPay);
                                
                            }
                        }
                    }
                ]
            }
            ,{
                
                xtype: 'panel',
                autoShow: true,
                autoScroll: true,
                enableToggle: true,
                title:'Print Preview PDF',
                id: 'panelpay_c',
                region: 'center',
                margins: '5 5 5 5',
                layout: 'fit',                
                tools: [{
                        type: 'maximize',
                        tooltip: 'Maximize Print Preview' 
                        ,listeners:{
                            click:function()   {
                                if(printUrlPay){
                                    var winprintpay=Ext.create('winprint2');
                                    winprintpay.maximize();
                                    to_print('printoutpdf2', printUrlPay); 
                                }
                                                                
                                                                
                                                                                        
                            }
                        }
                    }],
                html:'<iframe style="width:100%;height:100%;" id="printpay" src=""></iframe>'
                
            }
        ]
    },
    function(){
        combothajaranStorePay.load();
        allsiswaStoreBase.load();
        twinsiswaBaseStore.load();
        comboKelasStorePay.load();
    }
);
</script>
